home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Delphi Informant Complete 1995 - 2000
/
Delphi Informant Complete 1995 to 2000.iso
/
Delphi Informant Magazine Complete Works SOURCE CODE 1995.rar
/
1995
/
DEC
/
DI9512DH
/
mdiframe.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1995-10-25
|
5KB
|
171 lines
unit MDIFrame;
interface
uses WinTypes, WinProcs, Classes, Graphics, Controls, Printers,
Menus, MDIEdit, Dialogs, Forms, IniFiles;
type
TFrameForm = class(TForm)
OpenFileDialog: TOpenDialog;
MainMenu1: TMainMenu;
Open1: TMenuItem;
Window1: TMenuItem;
Tile1: TMenuItem;
Cascade1: TMenuItem;
ArrangeIcons1: TMenuItem;
Separator3: TMenuItem;
MRUSeparator: TMenuItem;
MRU1: TMenuItem;
MRU2: TMenuItem;
MRU3: TMenuItem;
MRU4: TMenuItem;
procedure NewChild(Sender: TObject);
procedure OpenChild(Sender: TObject);
procedure Exit1Click(Sender: TObject);
procedure Tile1Click(Sender: TObject);
procedure Cascade1Click(Sender: TObject);
procedure ArrangeIcons1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure MRUUpdate(Sender: TObject; const AddFilename: String);
procedure MRUDisplay(Sender: TObject);
procedure MRUOpenChild(Sender: TObject);
public
MRUList: TStringList; {Declare MRUList StringList variable}
end;
var
FrameForm: TFrameForm;
implementation
uses SysUtils;
{$R *.DFM}
procedure TFrameForm.NewChild(Sender: TObject);
var
EditForm: TEditForm;
begin
EditForm := TEditForm.Create(Application);
EditForm.Show;
end;
procedure TFrameForm.OpenChild(Sender: TObject);
var
EditForm: TEditForm;
begin
if OpenFileDialog.Execute then
begin
EditForm := TEditForm.Create(Self);
EditForm.Open(OpenFileDialog.Filename);
EditForm.Show;
EditForm.MRUDisplay(Sender); {Update MRU menu items}
end;
end;
procedure TFrameForm.Exit1Click(Sender: TObject);
begin
Close;
end;
procedure TFrameForm.Tile1Click(Sender: TObject);
begin
Tile;
end;
procedure TFrameForm.Cascade1Click(Sender: TObject);
begin
Cascade;
end;
procedure TFrameForm.ArrangeIcons1Click(Sender: TObject);
begin
ArrangeIcons;
end;
procedure TFrameForm.FormCreate(Sender: TObject);
var
AppIni: TIniFile; {Declare INI File variable}
Index: Integer;
begin
MRUList := TStringList.Create; {Create MRUList}
AppIni:= TIniFile.Create('TEXTEDIT.INI'); {Create IniFile}
for Index := 0 to 3 do {Loop to read all 4 items from Ini}
MRUList.Add(AppIni.ReadString('MRU', IntToStr(Index), ''));
AppIni.Free; {Free IniFile variable}
MRUDisplay(Sender); {Update MRU menu items}
end;
procedure TFrameForm.FormDestroy(Sender: TObject);
var
AppIni: TIniFile; {Delare IniFile variable}
Index: Integer;
begin
AppIni := TIniFile.Create('TEXTEDIT.INI'); {Create IniFile}
for Index := 0 to 3 do {Loop to write all 4 items to Ini}
AppIni.WriteString('MRU', IntToStr(Index), MRUList[Index]); {Save MRUList}
AppIni.Free;
end;
procedure TFrameForm.MRUUpdate(Sender: TObject;
const AddFileName: string);
var
Index: Integer; { Declare index variable }
begin
Index := 0;
{ Compare AddFileName to MRUList items }
while Index < (MRUList.count - 1) do
if AddFileName = MRUList[Index] then
{ If already there, delete each occurrence }
MRUList.delete(Index)
else
{ If not, update Index and try next item }
Index := Index + 1;
while MRUList.count > 3 do
MRUList.delete(MRUList.Count - 1);
while MRUList.count < 3 do
{ Keep MRUList }
MRUList.add('');
{ Then add fourth item to the top }
MRUList.Insert(0,AddFilename);
end;
procedure TFrameForm.MRUDisplay(Sender: TObject);
begin
MRU1.Caption := '&1 ' + MRUList[0]; {Set MRU menu item caption}
MRU1.Visible := (MRUList[0] <> ''); {Visible if not blank}
MRUSeparator.Visible := (MRUList[0] <> ''); {Seperator vis. if not blank}
MRU2.Caption := '&2 ' + MRUList[1];
MRU2.Visible := (MRUList[1] <> '');
MRU3.Caption := '&3 ' + MRUList[2];
MRU3.Visible := (MRUList[2] <> '');
MRU4.Caption := '&4 ' + MRUList[3];
MRU4.Visible := (MRUList[3] <> '');
end;
procedure TFrameForm.MRUOpenChild(Sender: TObject);
{Mimmics OpenChild, uses MRU item instead of Open Dialog}
var
EditForm: TEditForm;
Index: Integer;
begin
Index := TMenuItem(Sender).Tag; {Set Index using Sender.Tag}
if MRUList[Index] <> '' then
begin
EditForm := TEditForm.Create(Self);
EditForm.open(MRUList[Index]);
EditForm.show;
EditForm.MRUDisplay(Sender); {Update MRU menu items}
end;
end;
end.